package main

import (
	"flag"
	"log"
	"time"
)

var input = flag.Int("num", 12, "get input")

func fibonacci(c, quit chan int) {
	x, y := 1, 1
	for {
		select {
		case c <- x:
			x, y = y, x+y
		case <-quit:
			// fmt.Println("quit")
			return
		}
	}
}

func singleFab(num int) {

	c := make(chan int)
	quit := make(chan int)

	go func() {
		for i := 0; i < num; i++ {
			<-c
		}
		quit <- 0
	}()
	fibonacci(c, quit)

}

func calfab_time(num int) time.Duration {
	start_time := time.Now()
	singleFab(num)
	// end_time := time.Now()

	// duration := end_time.Sub(start_time)
	elapsed := time.Since(start_time)
	log.Printf("%d took %s", num, elapsed)
	// fmt.Println(duration)
	return elapsed
}

func main() {
	flag.Parse()
	for index := 1; index < *input; index++ {
		calfab_time(index)
	}

}
